package chances.epg.entity.content;


import java.awt.Rectangle;

import chances.epg.entity.AccessEntity;

public class SubjectArea extends AccessEntity {
	/**
	 * serialVersionUID.
	 */
	private static final long serialVersionUID = 3602028103263260454L;

	/**
	 * 单剧集
	 */
	public static final String OBJTYPE_VOD = "vod";

	/**
	 * 连续剧
	 */
	public static final String OBJTYPE_SERIES = "series";

	/**
	 * page
	 */
	public static final String OBJTYPE_PAGE = "page";

	public static final String OBJTYPE_BIZ = "biz";

	public static final String OBJTYPE_URL = "url";
	
	public static final String OBJTYPE_CHANNEL = "channel";
	
	public static final String OBJTYPE_LINK = "link";
	
	/**
	 * 系列剧
	 */
	public static final String OBJTYPE_SERIES2 = "series2";
	
	public static final String OBJLINKTYPE_VOD_PLAY = "vod_play";
	
	public static final String OBJLINKTYPE_VOD_det = "vod_detail";

	private Long id;
	private String pageCode;
	private String location;
	private String objType;
	private String objCode;
	private int defaultArea;
	
	private String linkType;   //链接类型
	private String picPath;    //图片路径
	private String displayType;//显示类型

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getPageCode() {
		return pageCode;
	}

	public void setPageCode(String pageCode) {
		this.pageCode = pageCode;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public String getObjType() {
		return objType;
	}

	public void setObjType(String objType) {
		this.objType = objType;
	}

	public String getObjCode() {
		return objCode;
	}

	public void setObjCode(String objCode) {
		this.objCode = objCode;
	}

	public int getDefaultArea() {
		return defaultArea;
	}

	public void setDefaultArea(int defaultArea) {
		this.defaultArea = defaultArea;
	}

	public int getLeft() {
		String[] posItems = this.getLocation().split(",");
		return Integer.parseInt(posItems[0]);
	}

	public int getTop() {
		String[] posItems = this.getLocation().split(",");
		return Integer.parseInt(posItems[1]);
	}

	public int getWidth() {
		String[] posItems = this.getLocation().split(",");
		int left1 = Integer.parseInt(posItems[0]);
		int left2 = Integer.parseInt(posItems[2]);
		return left2 - left1;
	}

	public int getHeight() {
		String[] posItems = this.getLocation().split(",");
		int top1 = Integer.parseInt(posItems[1]);
		int top2 = Integer.parseInt(posItems[3]);
		return top2 - top1;
	}

	public boolean isVod() {
		return OBJTYPE_VOD.equals(this.getObjType());
	}

	public boolean isSeries() {
		return OBJTYPE_SERIES.equals(this.getObjType());
	}
	
	public boolean isSeries2() {
		return OBJTYPE_SERIES2.equals(this.getObjType());
	}
	
	public boolean isGotoPlay() {
		return OBJLINKTYPE_VOD_PLAY.equals(this.getLinkType());
	}

	public boolean isPage() {
		return OBJTYPE_PAGE.equals(this.getObjType());
	}

	public Rectangle getRect() {

		Rectangle coordsRect = parseRectangle(location);
		int width = coordsRect.width - coordsRect.x;
		int height = coordsRect.height - coordsRect.y;
		coordsRect.setSize(width, height);
		return coordsRect;

	}
	


	public static Rectangle parseRectangle(String str) {
		String[] xywh = str.split(",");
		return new Rectangle(Integer.parseInt(xywh[0]), Integer.parseInt(xywh[1]), Integer.parseInt(xywh[2]),
				Integer.parseInt(xywh[3]));
	}

	public boolean isExternalUrl() {
		return OBJTYPE_URL.equals(this.getObjType());
	}

	public boolean isBiz() {
		return OBJTYPE_BIZ.equals(this.getObjType());
	}

	public String getLinkType() {
		return linkType;
	}

	public void setLinkType(String linkType) {
		this.linkType = linkType;
	}

	public String getPicPath() {
		return picPath;
	}

	public void setPicPath(String picPath) {
		this.picPath = picPath;
	}

	public String getDisplayType() {
		return displayType;
	}

	public void setDisplayType(String displayType) {
		this.displayType = displayType;
	}
}
